<template>
  <views class="enterprise_list">
    <viewTitle :title="'企业列表'" :border="true"></viewTitle>
    <div class="search_list">
      <el-form ref="form" :inline="true">
        <div class="flex flexR">
          <div class="inputW flex flexR center">
            <el-form-item label="企业编号:" label-width="auto">
              <el-input
                      style="width:200px"
                      type="text"
                      clearable
                      placeholder="企业编号"
                      v-model="enterprise_sn"
              ></el-input>
            </el-form-item>
          </div>
          <div class="inputW flex flexR center">
            <el-form-item label="企业名称:" label-width="90px">
              <el-input
                      style="width:200px"
                      type="text"
                      clearable
                      placeholder="企业名称"
                      v-model="enterprise_name"
              ></el-input>
            </el-form-item>
          </div>
          <div class="inputW flex flexR center">
            <el-form-item label="上级代理编号:" label-width="144px">
              <el-input
                      style="width:200px"
                      type="text"
                      clearable
                      placeholder="上级代理编号"
                      v-model="belong_agent_sn"
              ></el-input>
            </el-form-item>
          </div>

        </div>
      </el-form>

      <el-form ref="form" label-width="160px" :inline="true">
        <div class="flex flexR">
          <div class="inputW flex flexR center">
            <el-form-item label="企业状态:" label-width="auto">
              <el-select v-model="enterprise_status" placeholder="企业状态" clearable style="width:200px">
                <el-option
                        v-for="item in enterprise_status_select"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="inputW flex flexR center">
          <el-form-item label="所属服务商:" label-width="90px">
            <el-select v-model="facilitator_id" placeholder="所属服务商" filterable clearable style="width:200px">
              <el-option
                v-for="item in facilitator_select_list"
                :key="item.facilitator_id"
                :label="item.facilitator_name"
                :value="item.facilitator_id"
              ></el-option>
            </el-select>
          </el-form-item>
          </div>
          <div class="inputW flex flexR center">
            <el-form-item label="客户经理名称/编号:" label-width="144px">
              <el-input
                      style="width:200px"
                      type="text"
                      clearable
                      placeholder="客户经理名称/编号"
                      v-model="belong_client_manager_sn"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>

      <el-form ref="form" label-width="auto" :inline="true">
        <div class="flex flexR">
          <el-form-item label="提交时间:">
            <el-date-picker
              v-model="enterprise_created_time"
              value-format="timestamp"
              :default-time="['0:00:00','23:59:59']"
              type="datetimerange"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              align="right"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button @click="reSet" icon="el-icon-refresh">重置</el-button>
              <el-button
                type="primary"
                :style="{width:140+'px'}"
                @click="exportExcel"
                size="medium"
                icon="el-icon-download"
              >导出列表</el-button>
              <el-button type="primary" @click="query()" icon="el-icon-search">查询</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
      <!-- 
      <div class="search_unit">
        <el-button
          type="primary"
          :style="{width:140+'px'}"
          @click="exportExcel"
          size="medium"
          icon="el-icon-download"
        >导出列表</el-button>
      </div>
      <div class="search_unit">
        <el-button type="primary" @click="query()" icon="el-icon-search">查询</el-button>
      </div>-->
    </div>

    <div class="table_data">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="enterprise_sn" label="企业编号" width="190"></el-table-column>
        <el-table-column prop="enterprise_name" label="企业名称" width="180"></el-table-column>
        <el-table-column prop="enterprise_user" label="初始管理员账号" width="120"></el-table-column>
        <el-table-column prop="agent_sn" label="上级代理编号" width="150"></el-table-column>
        <el-table-column prop="agent_name" label="上级代理名称" width="120"></el-table-column>
        <el-table-column prop="facilitator_sn" label="所属服务商编号" width="180"></el-table-column>
        <el-table-column prop="facilitator_name" label="所属服务商" width="180"></el-table-column>
        <el-table-column prop="user_name" label="客户经理" width="120"></el-table-column>
        <el-table-column prop="contact_name" label="企业联系人" width="120"></el-table-column>
        <el-table-column prop="mobile" label="手机号码" width="120"></el-table-column>
        <el-table-column prop="province" label="所属地区" width="80"></el-table-column>
        <el-table-column prop="status" label="状态" width="60"></el-table-column>
        <el-table-column prop="enterprise_created_time" label="创建时间" width="180"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100" v-show="isLook">
          <template slot-scope="scope">
            <el-button type="primary" @click="look(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paging flex flexR">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="total, sizes,prev, pager, next, jumper"
          @size-change="handleSizeChange($event)"
          @current-change="changePage($event)"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>





<script>
export default {
  name: "TerraceAdministrators",
  data() {
    return {
      enterprise_status_select: [
        //列表中，企业可选择状态
        {
          label: "待审核",
          value: 0
        },
        {
          label: "审核通过",
          value: 1
        },
        {
          label: "已冻结",
          value: 2
        },
        {
          label: "审核不通过",
          value: 3
        }
      ],
      pickerOptions: {
        //企业创建时间快捷方式选择插件
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      facilitator_select_list: [], //平台可选服务商列表
      facilitator_id: "", //选择的服务商ID
      enterprise_status: "", //列表中选中的企业状态
      enterprise_created_time: [], //企业创建时间范围
      enterprise_sn: "", //企业编号
      enterprise_name: "", //企业名称
      belong_agent_sn: "", //所属代理商编号
      belong_client_manager_sn: "", //所属客户经理编号
      tableData: [], //表格数据
      download_url: "",
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    };
  },
  mounted() {
    //获取平台可选服务商简易列表
    this.getSimpleFacilitatorList();

    //获取列表数据
    this.query();
  },
  computed: {
    //实时计算要传输的编辑参数
    post_data() {
      let data = {};
      if (
        this.enterprise_created_time &&
        this.enterprise_created_time.length > 0
      ) {
        data.enterprise_created_start_time = this.enterprise_created_time[0]/1000;
        data.enterprise_created_end_time =  this.enterprise_created_time[1]/1000;
      }
      data.facilitator_id = this.facilitator_id;
      data.enterprise_sn = this.enterprise_sn;
      data.enterprise_name = this.enterprise_name;
      data.enterprise_status = this.enterprise_status;
      data.belong_agent_sn = this.belong_agent_sn;
      data.belong_client_manager_sn = this.belong_client_manager_sn;
      data.enterprise_sn = this.enterprise_sn;
      data.facilitator_id = this.facilitator_id;
      data.pagination = this.pagination;
      return data;
    },
    isLook(){      //判断是否具有 “查看” 按钮权限
      return  this.$store.state.buttonPermission[this.$route.path]  &&  this.$store.state.buttonPermission[this.$route.path].look ? 1 : 0;
    },
  },
  methods: {
    getSimpleFacilitatorList() {
      this.$raxios
        .post(this.$mapapi.getSimpleFacilitator, {})
        .then(res => {
          if (res.code != 200 && res.code != 501)
            return Promise.reject(res.msg);
          this.facilitator_select_list = res.data;
        })
        .catch(res => {
          this.$message.error(res);
        });
    },
    handleSizeChange(page_size) {
      //变动每页数量时
      this.pagination.page_size = page_size;
      this.query();
    },
    changePage(current_page) {
      //切换页码时
      this.pagination.page_start = current_page;
      this.query();
    },
    query() {
      //获取列表数据
      this.$raxios
        .post(this.$mapapi.enterpriseList, { data: this.post_data })
        .then(res => {
          if (res.code != 200 && res.code != 501)
            return Promise.reject(res.msg);
          this.tableData = res.data.list;
          this.pagination = res.data.pagination;
          this.download_url = res.data.download_url || "";
          console.log("user_list", res);
        })
        .catch(res => {
          this.$message.error(res);
        });
    },
    //导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    look(data) {
      let enterprise_id = data.enterprise_id;
      this.$toRoutePath({
        path: "/enterprise_list/enterprise_list_look",
        edit: true,
        query: { enterprise_id }
      });
    },
    reSet() {
        this.facilitator_id = ""; //选择的服务商ID
        this.enterprise_status= ""; //列表中选中的企业状态
        this.enterprise_created_time= []; //企业创建时间范围
        this.enterprise_sn = ""; //企业编号
        this.enterprise_name= ""; //企业名称
        this.belong_agent_sn="";  //所属代理商编号
        this.belong_client_manager_sn= ""; //所属客户经理编号
        this.query();
    }
  }
};
</script>


<style  lang="less" :scope="true" src="@/style/enterprise/enterprise_list.less">
</style>
